/*
 * Copyright 2011 OpenWAF.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.openwaf.client.ui;

import com.openwaf.client.dom.Element;
import com.openwaf.client.dom.Node;
import com.openwaf.client.event.Event;
import com.openwaf.client.event.EventHandler;

import com.openwaf.client.event.HandlerRegistration;
import com.openwaf.client.event.dom.BlurHandler;
import com.openwaf.client.event.dom.ChangeHandler;
import com.openwaf.client.event.dom.ClickHandler;
import com.openwaf.client.event.dom.ContextMenuHandler;
import com.openwaf.client.event.dom.DoubleClickHandler;
import com.openwaf.client.event.dom.FocusHandler;
import com.openwaf.client.event.dom.HasAllKeyHandlers;
import com.openwaf.client.event.dom.HasAllMouseHandlers;
import com.openwaf.client.event.dom.HasBlurHandlers;
import com.openwaf.client.event.dom.HasChangeHandlers;
import com.openwaf.client.event.dom.HasClickHandlers;
import com.openwaf.client.event.dom.HasContextMenuHandlers;
import com.openwaf.client.event.dom.HasDoubleClickHandlers;
import com.openwaf.client.event.dom.HasFocusHandlers;
import com.openwaf.client.event.dom.KeyDownHandler;
import com.openwaf.client.event.dom.KeyPressHandler;
import com.openwaf.client.event.dom.KeyUpHandler;
import com.openwaf.client.event.dom.MouseDownHandler;
import com.openwaf.client.event.dom.MouseMoveHandler;
import com.openwaf.client.event.dom.MouseOutHandler;
import com.openwaf.client.event.dom.MouseOverHandler;
import com.openwaf.client.event.dom.MouseUpHandler;
import com.openwaf.client.ui.annotation.ViewElement;
import com.openwaf.client.ui.annotation.ViewProperty;
import com.openwaf.common.annotation.EnsureIdentifier;

public class UIControl implements
        HasAllKeyHandlers,
        HasAllMouseHandlers,
        HasBlurHandlers,
        HasChangeHandlers,
        HasClickHandlers,
        HasContextMenuHandlers,
        HasDoubleClickHandlers,
        HasFocusHandlers {

    //Do not change this name used in compiler
    @ViewElement
    @EnsureIdentifier
    private Element elm = null;

    public UIControl() {
    }
    private final void __iv(){}

    public final Element getElement() {
        return elm;
    }
    public static native boolean hasUIControl(Node e)/*-{
        if(e==null)return false;
        return e._wo_!=undefined;
     }-*/;
    public static native UIControl getUIControl(Node e)/*-{
        if(e==null)return false;
        if(e._wo_!=undefined)
            return e._wo_;
        return null;
     }-*/;
    protected final void setElement(Element other){
        elm=other;
    }

    public void addCssClassName(String name) {
        elm.addCssClassName(name);
    }

    @ViewProperty
    public void setCssClassName(String name) {
        elm.setCssClassName(name);
    }

    public String getCssClassName() {
        return elm.getCssClassName();
    }

    public String[] getCssClassNames() {
        return elm.getCssClassNames();
    }

    public void removeCssClassName(String name) {
        elm.removeCssClassName(name);
    }

    public int getOffsetHeight() {
        return elm.getOffsetHeight();
    }

    public int getOffsetWidth() {
        return elm.getOffsetWidth();
    }

    public String getTitle() {
        return elm.getTitle();
    }

    @ViewProperty
    public void setTitle(String title) {
        elm.setTitle(title);
    }

    @ViewProperty
    public void setHeight(String height) {
        elm.getStyle().setHeight(height);
    }

   
    public void setHeight(int height) {
        elm.getStyle().setHeight(height + "px");
    }

    public String getHeight() {
        return elm.getStyle().getHeight();
    }

    @ViewProperty
    public void setWidth(String width) {
        elm.getStyle().setWidth(width);
    }

    public void setWidth(int width) {
        elm.getStyle().setWidth(width + "px");
    }

    public String getWidth() {
        return elm.getStyle().getWidth();
    }

    public void setSize(int height, int width) {
        elm.getStyle().setHeight(height + "px");
        elm.getStyle().setWidth(width + "px");
    }

    @ViewProperty
    public void setSize(String height, String width) {
        elm.getStyle().setHeight(height);
        elm.getStyle().setWidth(width);
    }

    public HandlerRegistration addKeyDownHandler(KeyDownHandler handler) {
        return elm.addKeyDownHandler(handler);
    }

    public HandlerRegistration addKeyUpHandler(KeyUpHandler handler) {
        return elm.addKeyUpHandler(handler);
    }

    public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
        return elm.addKeyPressHandler(handler);
    }

    public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
        return elm.addMouseDownHandler(handler);
    }

    public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
        return elm.addMouseMoveHandler(handler);
    }

    public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
        return elm.addMouseOutHandler(handler);
    }

    public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
        return elm.addMouseOverHandler(handler);
    }

    public HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
        return elm.addMouseUpHandler(handler);
    }

    public HandlerRegistration addBlurHandler(BlurHandler handler) {
        return elm.addBlurHandler(handler);
    }

    public HandlerRegistration addChangeHandler(ChangeHandler handler) {
        return elm.addChangeHandler(handler);
    }

    public HandlerRegistration addClickHandler(ClickHandler handler) {
        return elm.addClickHandler(handler);
    }

    public HandlerRegistration addContextMenuHandler(ContextMenuHandler handler) {
        return elm.addContextMenuHandler(handler);
    }

    public HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler) {
        return elm.addDoubleClickHandler(handler);
    }

    public HandlerRegistration addFocusHandler(FocusHandler handler) {
        return elm.addFocusHandler(handler);
    }

    public void fireEvent(Event<?> event) {
        elm.fireEvent(event);
    }

    public void removeEventHandler(EventHandler handler) {
        elm.removeEventHandler(handler);
    }

    public boolean hasEventHandlersForType(String type) {
        return elm.hasEventHandlersForType(type);
    }
}
